package com.guli.gulimall.gulimallware.service.impl;

import com.guli.gulimall.gulimallware.entity.PurchaseEntity;
import lombok.val;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.Query;

import com.guli.gulimall.gulimallware.dao.PurchaseDetailDao;
import com.guli.gulimall.gulimallware.entity.PurchaseDetailEntity;
import com.guli.gulimall.gulimallware.service.PurchaseDetailService;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        key:
//        status:
//        wareId:
        QueryWrapper<PurchaseDetailEntity> objectQueryWrapper = new QueryWrapper<>();

        String key = (String) params.get("key");
        if(null!=key && !key.isEmpty() && !"0".equalsIgnoreCase(key)){
            objectQueryWrapper.and(w->{
                w.eq("purchase_id",key).or().eq("sku_id",key);
            });
        }

        String status = (String) params.get("status");
        if(null!=status && !status.isEmpty()){
            objectQueryWrapper.eq("status",status);
        }

        String wareId = (String) params.get("wareId");
        if(null!=wareId && !wareId.isEmpty() && !"0".equalsIgnoreCase(wareId)){
            objectQueryWrapper.eq("ware_id",wareId);
        }

        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                objectQueryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public List<PurchaseDetailEntity> listDetailPurchaseId(Long item) {

        return this.list(new QueryWrapper<PurchaseDetailEntity>().eq("purchase_id",item));
    }

}